<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><{$Think.config.cfg_webname}></title>
    <link href="__CSS__/base.css" rel="stylesheet">
    <link rel="stylesheet" href="__PUBLIC__/custom/uimaker/easyui.css">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/custom/uimaker/icon.css">
    <style>
        #formAdd table{ width:100%;}
        #formAdd table td{ padding:5px;}
        #formAdd table td.td-left{text-align: right; padding-right: 10px;}
    </style>
</head>
<body>
<div class="container">
    <table id="cxdm"></table>
    <div id="DivAdd" class="easyui-dialog" style="width:450px;height:250px;padding:10px 20px"
         closed="true" resizable="true" modal="true" data-options="iconCls: 'icon-add',buttons: '#dlg-buttons'">
        <form id="formAdd" method="post" novalidate="novalidate">
            <input type="hidden" id="action" name="action">
            <input type="hidden" id="id" name="id">
            <table>
                <tr>
                    <td class="td-left" width="25%">属性名称:</td>
                    <td width="75%"><input class="easyui-textbox" type="text" name="flagname" data-options="required:true" style="height:30px;"></td>
                </tr>
                <tr>
                    <td class="td-left">属性标识:</td>
                    <td><input class="easyui-textbox" type="text" name="flag" data-options="required:true" style="height:30px;"></td>
                </tr>
                <tr>
                    <td class="td-left">排序:</td>
                    <td><input class="easyui-numberspinner" value="1" name="orderid" data-options="increment:1,required:true" style="height:30px;"></td>
                </tr>
            </table>
        </form>
    </div>
    <div id="dlg-buttons">
        <div style="text-align:right;">
            <a href="javascript:void(0)" class="easyui-linkbutton" id="btnAddOK" iconcls="icon-ok" onclick="btnAddOK()">确定</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#DivAdd').dialog('close')">关闭</a>
        </div>
    </div>
</div>
<div id="tb" style="padding:0 30px;">
    <div>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="selected:true" onclick = "addInfoFlagData()">新增</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" data-options="selected:true" onclick = "editInfoFlagData()">修改</a>
    </div>
</div>

<script type="text/javascript" src="__PUBLIC__/custom/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/custom/jquery.easyui.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/custom/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">

    $(function(){
        //加载数据
        $('#cxdm').datagrid({
            title:'信息标记管理',
            width:'100%',
            height:$(window).height(),
            fitColumns:true,
            striped: true,
            checkOnSelect:true,
            singleSelect : true,
            frozenColumns:[[//在冻结列中加入多选框
                {field:'chek',checkbox:true}
            ]],
            url:'<{:U("Info/getInfoFlag")}>',
            loadMsg:'数据加载中请稍后……',
            pagination: false,
            rownumbers: false,
            pageSize:10,
            toolbar:'#tb',
            columns:[[
                {field:'id',title: 'ID',align: 'center',sortable:"true",width:50},
                {field:'flagname',title: '属性名称',align: 'center',width:100,},
                {field:'flag',title: '属性标识',align: 'center',width:100},
                {field:'orderid',title: '排序',align: 'center',width:50},
//                {field:'operate',title: '操作',align: 'center',width:100,
//                    formatter:function(val,row,index){
//                        return "<a href = '<{:U("Cascade/casCadeData")}>/sign/"+row.groupsign+"'>查看</a>";
//                    }
//                },
            ]],
        });
    });

    //修改
    function editInfoFlagData(id){
        var arr=$('#cxdm').datagrid('getSelections');
        if(!arr[0]){
            $.messager.alert('提示','请选择一条数据!');
            return false;
        }
        $("#DivAdd").dialog('open').dialog('setTitle', '修改信息标记');
        $('#formAdd').form('load',arr[0]);
        $('#action').val("update");
    }

    function addInfoFlagData(){
        $("#DivAdd").dialog('open').dialog('setTitle', '新增信息标记');
        $('#formAdd').form('clear');
        $('#action').val("add");
    }

    function reload(){
        window.location.reload();
    }


    function btnAddOK() {
        $('#formAdd').form('submit',{
            url: '<{:U("Info/addInfoFlag")}>',
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                var result = eval('('+result+')');
                console.log(result.success);
                if (result.success){
                    if(!result.id){
                        $.messager.confirm('提示', '添加成功，继续添加?', function(r){
                            if (r){
                                $('#formAdd').form('clear');
                            }else{
                                reload();
                            }
                        });
                    }else{
                        $.messager.alert('提示','修改成功!','info',function(){
                            reload();
                        });
                    }
                } else {
                    $.messager.show({
                        title: '错误提示',
                        msg: result.msg
                    });
                }
            }
        });
    }
</script>
</body>
</html>

